#include <QFileInfo>

#include "downloaddialog.h"
#include "ui_downloaddialog.h"

namespace Jcr
{

DownloadDialog::DownloadDialog(QWidget* parent) :QDialog(parent)
{
    m_ui = new Ui::DownloadDialog;
    m_ui->setupUi(this);
    m_ui->urlEdit->setFocus();

    connect(m_ui->urlEdit, SIGNAL(textChanged(QString)), this, SLOT(onUrlChanged(QString)));
}

void DownloadDialog::setUrl(const QString& url)
{
    m_ui->urlEdit->setText(url);
}

QString DownloadDialog::url() const
{
    return m_ui->urlEdit->text();
}

void DownloadDialog::setSaveDir(const QString& dir)
{
    m_ui->saveDirEdit->setText(dir);
}

QString DownloadDialog::saveDir() const
{
    return m_ui->saveDirEdit->text();
}

void DownloadDialog::setSaveName(const QString& saveName)
{
    m_ui->saveNameEdit->setText(saveName);
}

QString DownloadDialog::saveName() const
{
    return m_ui->saveNameEdit->text();
}

void DownloadDialog::onUrlChanged(const QString &url)
{
    QFileInfo fi(url);
    m_ui->saveNameEdit->setText(fi.baseName());
}

} // namespace jcr
